Thread: struct mystruct mystruct = { item1: value, . . .

  1. #16
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Named structure initialization. A GCC extension. Non-standard, and extremely useful.

    Does that mean we should burn the GCC authors in hell? Nah.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  2. #17
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by brewbuck View Post
    Named structure initialization. A GCC extension. Non-standard, and extremely useful.
    For the record, named initializers were introduced in the C99 standard, but have to use a dot. Check section 6.7.8, item 34 of this document: http://www.open-std.org/jtc1/sc22/wg...docs/n1124.pdf.

    Named initializers using a : are a GNU extension that they deprecated in gcc 2.5! Check the current docs here: Designated Inits - Using the GNU Compiler Collection (GCC). Very old stuff, considering the current version is 4.5.1. So, using .member to initialize is fine and should be portable. Using the : is not and should be avoided.

  3. #18
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    brewbuck.... So long as you realize it is non-standard and may not be supported either in other compilers or future releases of GCC... I don't see the problem.

    That said... I would probably never use it.

  4. #19
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Quote Originally Posted by anduril462 View Post
    Named initializers using a : are a GNU extension that they deprecated in gcc 2.5! Check the current docs here: Designated Inits - Using the GNU Compiler Collection (GCC). Very old stuff, considering the current version is 4.5.1. So, using .member to initialize is fine and should be portable. Using the : is not and should be avoided.
    Hmmm, I'm using 4.4.1 to cross compile the kernel -- not even a hit of a warning about it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with Realloc()
    By krazyxazn in forum C Programming
    Replies: 10
    Last Post: 01-27-2010, 10:05 PM
  2. help with structs and malloc!
    By coni in forum C Programming
    Replies: 20
    Last Post: 09-14-2009, 05:38 PM
  3. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  4. Function validation.
    By Fhl in forum C Programming
    Replies: 10
    Last Post: 02-22-2006, 08:18 AM
  5. Search Engine - Binary Search Tree
    By Gecko2099 in forum C Programming
    Replies: 9
    Last Post: 04-17-2005, 02:56 PM